import { ref, onMounted } from 'vue'

export const useTopDistance = (selector) => {
  // 元素到顶部的距离
  const TOP_DISTANCE = ref(0)
  // 自定义导航条高度
  const NAV_BAR_HEIGHT = 176

  onMounted(() => {
    uni
      .createSelectorQuery()
      .select(selector)
      .boundingClientRect((res) => {
        TOP_DISTANCE.value = res.top - uni.upx2px(NAV_BAR_HEIGHT)
      })
      .exec()
  })
  return {
    TOP_DISTANCE
  }
}
